import { defineStore } from "pinia";
import { carList, deleteCarList, addCarList } from "../api/index.js";
export const useCarStore = defineStore("car", {
  state: () => {
    return {
      list: [],
    };
  },
  getters: {},
  actions: {
    // 获取商品列表
    getInfo(eid) {
      return carList(eid).then((res) => {
        this.list = res.data.data.listCarts;
        // console.log(this.list);
      });
    },
    deleteInfo(cid) {
      return deleteCarList(cid)
        .then((res) => {
          // console.log(111);
          // console.log(res);
        })
        .catch((err) => {
          // console.log(222);
        });
    },
    // 加入购物车
    addInfo(total, gnid, eid) {
      return addCarList(total, gnid, eid);
    },
  },
});
